#include<stdio.h>
#include<windows.h>
#pragma comment(lib,"winmm.lib")
#define _CRT_SECURE_NO_WARNINGS 
#include<time.h>
#include <conio.h>
#include <dos.h>

int c = 0;
int e1 = 0;
int e2 = 0;
int d = 0;
int t = 0;
int tick = 0;
int* e1_ = &e1;
int* e2_ = &e2;
int* c_ = &c;
int* d_ = &d;
int* t_ = &t;
int* tick_ = &tick;

LONG WINAPI TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);// 声明一个定时器处理函数

int input()
{
  if (_kbhit())
  { 
    *c_ = *c_ * 10;
   
    switch (_getch())
    {
    case 48: *c_ = *c_ + 0;
      break;
    case 49: *c_ = *c_ + 1;
      break;
    case 50: *c_ = *c_ + 2;
      break;
    case 51: *c_ = *c_ + 3;
      break;
    case 52: *c_ = *c_ + 4;
      break;
    case 53: *c_ = *c_ + 5;
      break;
    case 54: *c_ = *c_ + 6;
      break;
    case 55: *c_ = *c_ + 7;
      break;
    case 56: *c_ = *c_ + 8;
      break;
    case 57: *c_ = *c_ + 9;
      break;
    case 43: *e1_ = 1;//加
      *c_ = *c_ / 10;
      *t_ = 1;
      break;
    case 45: *e1_ = 2;//减
      *c_ = *c_ / 10;
      *t_ = 2;
      break;
    case 42: *e1_ = 3;//乘
      *c_ = *c_ / 10;
      *t_ = 3;
      break;
    case 47: *e1_ = 4;//除
      *c_ = *c_ / 10;
      *t_ = 4;
      break;
    case 13: *e1_ = 5;//回车等于
      *c_ = c / 10;
      *t_ = 0;
      break;
    /*case 65: *c_ = c / 10;
      *tick_ = 1;
      break;*/
    case 0:  *c_ = *c_ / 10;    
      break;
    default: *c_ = *c_ / 10;
      
      break;
    }
  }
}

int test1()
{
  if (*e1_ != 0)
  {
    if (*e2_ == 0)
    {
      *d_ = *c_;
      *c_ = 0;
    }
    else if (*e2_ == 1)
    {
      *d_ = *d_ + *c_;
      *c_ = 0;     
    }
    else if (*e2_ == 2)
    {
      *d_ = *d_ - *c_;
      *c_ = 0;     
    }
    else if (*e2_ == 3)
    {
      *d_ = *d_ * *c_;
      *c_ = 0;     
    }
    else if (*e2_ == 4)
    {
      *d_ = *d_ / *c_;
      *c_ = 0;
    }
    *e2_ = *e1_;
    *e1_ = 0;
  }
  /*printf("%d-%d\n", *d_, *c_);
  printf("%d--%d\n", *e2_, *e1_);*/

}

int output()
{
  system("color 70");
  printf("%d", *d_);
  if (*t_ == 0)
  {
    printf("   ");
  }
  if (*t_ == 1)
  {
    printf(" + ");
  }
  if (*t_ == 2)
  {
    printf(" - ");
  }
  if (*t_ == 3)
  {
    printf(" * ");
  }
  if (*t_ == 4)
  {
    printf(" / ");
  }
  printf("%d", *c_);
  Sleep(170);
  system("cls"); 
}

//int way2()
//{
//  if (*tick_ == 1)
//  {
//    printf("1111");
//    Sleep(100);
//    scanf_s("%d", &*tick_);
//    int arr[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
//    int a = 0;
//    int b = 0;
//    b = (*tick_ + 7) % 7;
//    if (b == 0)
//    {
//      b = 7;
//    }
//    for (int i = 0; i <= 12; i++)
//    {
//      if (*tick_ > 0)
//      {
//        a = *tick_;
//        *tick_ = *tick_ - arr[i];
//      }
//      else
//      {
//        *tick_ = i;
//        break;
//      }
//
//    }
//    printf("2024年");
//    printf("%d月", tick);
//    printf("%d日", a);
//    printf("星期%d\n", b);
//    system("pause");
//    *tick_ = 0;
//  }
//  
//}

int main() {
  // 创建窗口句柄
  HWND hWnd = CreateWindow(
    "static", NULL, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, NULL, NULL);

  // 设置定时器
  SetTimer(hWnd, 1, 200, (TIMERPROC)TimerProc); // 每0.5秒触发一次定时器

  // 主消息循环
  MSG msg;
  while (GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  // 销毁定时器
  KillTimer(hWnd, 1);
  return 0;
}

LONG WINAPI TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) // 定时器触发时的处理
{ 
  input();
  test1();
  output();// 可以根据需要在这里进行多媒体操作
  //way2();
  return 0;
}
